﻿<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:ItemsAnimation="clr-namespace:ItemsAnimation"
    xmlns:ComponentModel="clr-namespace:System.ComponentModel;assembly=WindowsBase" xmlns:AnimationAdditions="clr-namespace:AnimationAdditions;assembly=AnimationAdditions" xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions" x:Class="ItemsAnimation.MainWindow"
    Title="MainWindow" Height="400" Width="400" DataContext="{Binding RelativeSource={RelativeSource Self}}">
	<Window.Resources>
        <CollectionViewSource x:Key="objectCollection" Source="{Binding Items}">
            <CollectionViewSource.SortDescriptions>
                <ComponentModel:SortDescription PropertyName="FirstName" />
            </CollectionViewSource.SortDescriptions>
        </CollectionViewSource>
		<DataTemplate DataType="{x:Type ItemsAnimation:BusinessObject}">
			<Border BorderBrush="Gold" BorderThickness="2" CornerRadius="12">
				<Grid>
					<Grid.RowDefinitions>
						<RowDefinition />
						<RowDefinition />
					</Grid.RowDefinitions>
					<Grid.ColumnDefinitions>
						<ColumnDefinition />
						<ColumnDefinition />
					</Grid.ColumnDefinitions>
					<Image Source="{Binding ImagePath}" Grid.Row="0" Grid.ColumnSpan="2" />
					<Label Grid.Row="1" Grid.Column="0" Content="{Binding FirstName}" />
					<Label Grid.Row="1" Grid.Column="1" Content="{Binding LastName}" />
				</Grid>
			</Border>
		</DataTemplate>
	</Window.Resources>
	<Grid>
        <TabControl>
            <TabItem Header="Items Host">
                <Grid>
                    <Grid.Resources>
                        <Style TargetType="{x:Type Button}">
                            <Setter Property="Margin" Value="5" />
                        </Style>
                    </Grid.Resources>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*"/>
                        <RowDefinition Height="35"/>
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition />
                        <ColumnDefinition />
                        <ColumnDefinition />
                    </Grid.ColumnDefinitions>

                    <!-- When ItemsSource is binded to PreviewObservableCollection (Items property in MainWindow.xaml.cs) then sorting
                        function will not work but animated removing will work.
                         When ItemsSource is binded to CollectionViewSource (as in this case) then sorting will work. However, animated
                        animated removing won't be available.
                    -->
                    <AnimationAdditions:PreviewListBox Grid.Row="0" Grid.ColumnSpan="3"
                     ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                     ScrollViewer.VerticalScrollBarVisibility="Visible"
                     ScrollViewer.CanContentScroll="True" x:Name="listBox"
                     ItemsSource="{Binding Source={StaticResource objectCollection}}">
                        <ListBox.ItemsPanel>
                            <ItemsPanelTemplate>
                                <AnimationAdditions:AnimatedPanel x:Name="animatedPanel"
                                    ItemSize="{Binding ItemSize}"/>
                            </ItemsPanelTemplate>
                        </ListBox.ItemsPanel>
                    </AnimationAdditions:PreviewListBox>
                    
                    <Button Grid.Row="1" Grid.Column="3" Content="Sort" Click="SortButton_Click" />
                    <Button Grid.Row="1" Grid.Column="0" Content="Add" Click="Add_Click" x:Name="addButton" />
                    <Button Grid.Row="1" Grid.Column="1" Content="Remove" Click="Remove_Click" />
                </Grid>
            </TabItem>
            <TabItem Header="UI Elements">
                <TabItem.Resources>
                    <Style TargetType="{x:Type Button}">
                        <Setter Property="Width" Value="50" />
                        <Setter Property="Height" Value="50" />
                    </Style>
                </TabItem.Resources>
                <AnimationAdditions:AnimatedPanel x:Name="animatedPanel1"
                            Grid.Row="1" ItemSize="80">
                    <Button Content="Button 1"/>
                    <Button Content="Button 2"/>
                    <CheckBox Content="CheckBox" IsChecked="True" />
                    <Image Source="Images\12.jpg" />
                    <Rectangle Fill="Black" Width="45" Height="45"/>
                    <Ellipse Fill="Green" Width="45" Height="45" />
                    <TextBlock Text="This is text"/>
                    <TextBox Text="Text inside"/>
                    <RadioButton Content="RadioButton" />
                </AnimationAdditions:AnimatedPanel>
            </TabItem>
        </TabControl>
	</Grid>
</Window>
